package com.huifer.wgx.controller;

import com.huifer.wgx.model.RtkPointEntity;
import com.huifer.wgx.pojo.CommonResult;
import com.huifer.wgx.service.RtkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Title : RtkPointController </p>
 * <p>Description : rtk</p>
 *
 * @author huifer
 * @date 2019-03-15
 */
@RestController
@RequestMapping("rtk_point")
@Api(tags = "RtkPointController", description = "rtk点集管理")
public class RtkPointController {

    @Autowired
    private RtkService rtkService;
    private CommonResult commonResult = new CommonResult();


    @ApiOperation("将rtk文件内容保存到数据库")
    @PostMapping("/save")
    public ResponseEntity findAllRtk(
            @RequestParam("personnel_id") Long personnelId,
            @RequestParam("work_id") Long workid,
            @RequestParam("filename") String filename
    ) {
        try {
            List<RtkPointEntity> rtkList = rtkService.createList(personnelId, workid, filename);
            return ResponseEntity.ok(commonResult.success(rtkService.saveRtkList(rtkList)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("查询所有rkt")
    @GetMapping("/find_all")
    public ResponseEntity findAllRtk(
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity.ok(commonResult.success(rtkService.findAll(pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }


    @ApiOperation("根据工程id查询rtk")
    @GetMapping("/find_by_work_id")
    public ResponseEntity findRtkByWorkId(
            @RequestParam("workid") Long workId,
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult.success(rtkService.findByWorkId(workId, pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }

    @ApiOperation("根据负责人id查询rtk")
    @GetMapping("/find_by_personnel_id")
    public ResponseEntity findByPersonnelId(
            @RequestParam("personnelid") Long personnelId,
            @RequestParam("pagenum") Integer pageNum,
            @RequestParam("pagesize") Integer pageSize) {
        try {
            return ResponseEntity
                    .ok(commonResult
                            .success(rtkService.findByPersonnelId(personnelId, pageNum, pageSize)));
        } catch (Exception e) {
            return ResponseEntity.badRequest().body(commonResult.fialed(e));
        }
    }

}
